<template>
    <!-- table区域-begin -->
    <div>
      <a-config-provider>
        <template  #renderEmpty>
          <!-- <div style="text-align: center">
            <a-icon type="smile" style="font-size: 20px" />
            <p>Data Not Found</p>
          </div> -->
        </template>
        <div class="config-provider">
         <a-table
            ref="feesTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap"
            style="margin:2px 0;"
            :scroll="{x:true}"
            :columns="columns"
            :pagination="false"
            :dataSource="dataSource"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          >
           <template slot="ellipsisText" slot-scope="text">
            <j-ellipsis :value="text" :length="textMaxLength"></j-ellipsis>
          </template>

          </a-table>
        </div>
      </a-config-provider>

    </div>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction} from '@/api/manage'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'
  import JEllipsis from '@/components/jeecg/JEllipsis'

  export default {
    name: "ChgUniteFeesArrear",
    mixins:[JeecgListMixin],
    components: {

    },

    data () {
      return {
        description: '统一收费-费用列表',
        textMaxLength:5,
         // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '用户号',
            align: 'center',
            dataIndex: 'cusId'
          },
          {
            title: '用户名',
            align: 'center',
            dataIndex: 'cusName',
            scopedSlots: {customRender: "ellipsisText"}
          },
          {
            title: '用水性质',
            align: 'center',
            dataIndex: 'natureName'
          },
          {
            title: '月份',
            align: 'center',
            dataIndex: 'readMonth',
          },
          {
            title: '起度',
            align: 'center',
            dataIndex: 'beginScale',
          },
          {
            title: '止度',
            align: 'center',
            dataIndex: 'endScale',
          },
          {
            title: '计费水量',
            align: 'center',
            dataIndex: 'measureAmount',
          },
          {
            title: '水费',
            align: 'center',
            dataIndex: 'totalMoney',
          },
          {
            title:'污水费',
            align:"center",
            dataIndex: 'wuMoney'
          },
          {
            title:'垃圾费',
            align:"center",
            dataIndex: 'ljMoney'
          },
          {
            title: '杂项费',
            align: 'center',
            dataIndex: 'alienMoney',
          },
          {
            title: '增值税金额',
            align: 'center',
            dataIndex: 'vatMoney',
          },
          {
            title: '实计金额',
            align: 'center',
            dataIndex: 'money',
          },
          {
            title: '违约金',
            align: 'center',
            dataIndex: 'penalty',
          },
          // {
          //   title: '违约天数',
          //   align: 'center',
          //   dataIndex: 'penaltyDay',
          // },

          {
            title: '欠费金额',
            align: 'center',
            dataIndex: 'arrearMoney',
          },
          {
            title: '减免金额',
            align: 'center',
            dataIndex: 'derateMoney',
          },
          {
            title: '优惠金额',
            align: 'center',
            dataIndex: 'discountMoney',
          }
        ],
        url: {
          list: "/chg/chgArrears/feesList",
        },
        selectedMainId:'',
        dictOptions:{},
        dataSource:[],

      }
    },
    created() {

    },
    mounted(){

    },

    methods: {
      initDictConfig(){
      },
      onSelectChange(selectedRowKeys, selectionRows) {      
        // 找出没勾选的月份，与勾选最后一条比较      
        var noSelRow=null;
        for(var i=0;i<this.dataSource.length;i++){
          let isNoSel=1;
          for(var j=0;j<selectionRows.length;j++){
            if(this.dataSource[i].id == selectionRows[j].id ){
              isNoSel=0;
              break;
            }
          }
          if(isNoSel == 1){   
            noSelRow=this.dataSource[i];
            break;
          }
        }
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        if(noSelRow){
          let sl= selectionRows.length;
          let noSelMonth=Number.parseInt(noSelRow.readMonth) ;
          let maxMonth= Number.parseInt(selectionRows[sl-1].readMonth);
          if(maxMonth>noSelMonth){
             this.$message.warning("不允许跨月缴费")
          }
        }
        this.$emit('feeSelectChanges');
      },
      loadArrearData(data){
        if(data){
          this.dataSource=data;
          let ids=data.map(item=>{return item.id});
          let arr1 = [] ;
          arr1.push(ids);
          this.selectedRowKeys = arr1[0];
        }else{
          this.dataSource=[];
          this.onClearSelected();
          this.selectedMainId = '';
        }
      },
      getSelectDataRowIds(){
        return this.selectedRowKeys;
      },
      getSelectDataRowFees(){
        var arrearMoney=0.0;
        if(this.selectionRows.length>0){
          for(var i=0;i<this.selectionRows.length;i++){
            var row=this.selectionRows[i];
            arrearMoney = arrearMoney + (Number.parseFloat(row.arrearMoney) - Number.parseFloat(row.recivedMoney));
          }
        }
        return arrearMoney.toFixed(2);
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .feeInput{
    width: 100px;
  }
  .ant-table-body{
    min-height: 100px;
  }
  .ant-empty-normal{
    margin:2px 0;
  }

</style>